<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/1 0001
 * Time: 下午 8:15
 */

namespace App\Models\Traits;


use App\Models\Comment;
use App\Models\EduZan;
use App\User;

trait Common
{
    //与赞表进行多态关联
    public function zan(){
        return $this->morphMany(EduZan::class,'zan');
    }
    //与评论表进行多态关联
    public function comment(){
        return $this->morphMany(Comment::class,'comment');
    }

    //与用户关联,无论是一个赞还是一篇评论都只属于一个用户,通过belongsTo一对一关联
    public function user(){
        return $this->belongsTo(User::class);
    }

}